﻿namespace DotRas
{
    using pptpclient.Properties;
    using System;
    using System.Collections.ObjectModel;
    using System.Diagnostics;
    using System.Security.Permissions;

    [DebuggerDisplay("PhoneNumber = {PhoneNumber}"), PermissionSet(SecurityAction.Demand, Name="FullTrust")]
    public sealed class RasSubEntry : MarshalByRefObject, ICloneable
    {
        private Collection<string> _alternatePhoneNumbers;
        private RasDevice _device;
        private RasEntry _owner;
        private string _phoneNumber;

        public object Clone()
        {
            RasSubEntry entry = new RasSubEntry();
            if (this.AlternatePhoneNumbers.Count > 0)
            {
                foreach (string str in this.AlternatePhoneNumbers)
                {
                    entry.AlternatePhoneNumbers.Add(str);
                }
            }
            entry.Device = this.Device;
            entry.PhoneNumber = this.PhoneNumber;
            return entry;
        }

        public bool Remove()
        {
            bool flag = false;
            if (this.Owner != null)
            {
                flag = this.Owner.SubEntries.Remove(this);
            }
            return flag;
        }

        public bool Update()
        {
            if ((this.Owner == null) || (this.Owner.Owner == null))
            {
                DotRas.ThrowHelper.ThrowInvalidOperationException(Resources.Exception_EntryNotInPhoneBook);
            }
            bool flag = false;
            int index = this.Owner.SubEntries.IndexOf(this);
            if (index != -1)
            {
                flag = RasHelper.SetSubEntryProperties(this.Owner.Owner, this.Owner, index, this);
            }
            return flag;
        }

        public Collection<string> AlternatePhoneNumbers
        {
            get
            {
                if (this._alternatePhoneNumbers == null)
                {
                    this._alternatePhoneNumbers = new Collection<string>();
                }
                return this._alternatePhoneNumbers;
            }
            internal set
            {
                this._alternatePhoneNumbers = value;
            }
        }

        public RasDevice Device
        {
            get
            {
                return this._device;
            }
            set
            {
                this._device = value;
            }
        }

        public RasEntry Owner
        {
            get
            {
                return this._owner;
            }
            internal set
            {
                this._owner = value;
            }
        }

        public string PhoneNumber
        {
            get
            {
                return this._phoneNumber;
            }
            set
            {
                this._phoneNumber = value;
            }
        }
    }
}

